int servoPin = 8;     // Control pin for servo motor
int minPulse = 1000;   // Minimum servo position
int maxPulse = 2000;  // Maximum servo position
int pulse = 0;        // Amount to pulse the servo

int refreshTime = 500; // the time needed in between pulses

int analogValue = 0;  // the value returned from the analog sensor
int analogPin = 0;    // the analog pin that the sensor's on

int printTime=500;
float lastPrint=0;

void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulse = minPulse;           // Set the motor position value to the minimum
  Serial.begin(9600);
}

void loop() {
  analogValue = analogRead(analogPin);      // read the analog input
  pulse = (((float)analogValue / (float)1023)*minPulse) + minPulse; 

    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    delay(refreshTime);
    
        if (millis() - lastPrint >printTime){
      Serial.print(pulse,DEC);
      Serial.print("; ");
      Serial.println(analogValue, DEC);
      lastPrint=millis();
      }
}
